﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using DAL;
using Services;
using Ninject;
using Entities;
namespace WebUI
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        readonly IKernel ninjectKernel;

        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            IGenericRepository<FAEntities, AuditedOperation> repository = new GenericRepository<FAEntities, AuditedOperation>();
            ninjectKernel.Bind<IGenericFilesService>().To<GenericFilesService>().WithConstructorArgument("repository", repository);
            ninjectKernel.Bind<IFilterService>().To<FilterService>().WithConstructorArgument("repository", repository);
            ninjectKernel.Bind<IDetailsService>().To<DetailsService>().WithConstructorArgument("repository", repository);
        }
    }
}
